package com.itheima.网络编程.网络编程基础编程.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class udp接收数据 {
    public static void main(String[] args) throws Exception {
        //udpReceive1();
        udpReceive2();
    }

    private static void udpReceive2() throws IOException {
        DatagramSocket ds= null;
        while (true) {
            ds = new DatagramSocket(10088);
            byte[] bys=new byte[102481024];
            DatagramPacket dp=new DatagramPacket(bys,bys.length);
            ds.receive(dp);
            System.out.println(new String(dp.getData(),0,dp.getLength()));
            ds.close();
        }
    }




    public static void udpReceive1() throws IOException {
        while(true){
            DatagramSocket dgs=new DatagramSocket(10086);
            byte[] bys=new byte[1024*1024];
            DatagramPacket dgp=new DatagramPacket(bys,bys.length);
            dgs.receive(dgp);
            System.out.println(new String(dgp.getData(),0,dgp.getLength()));
            dgs.close();
        }
    }
}
